<%@page import="weaver.hrm.User"%>
<%@page import="com.weaver.formmodel.mobile.manager.MobileUserInit"%>
<%@page import="java.io.IOException"%>
<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.general.*" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sf.json.JSONArray"%>
<%@ page import="net.sf.json.JSONObject"%>
<%@ page import="weaver.formmode.search.FormModeTransMethod"%>
<%@ page import="weaver.formmode.customjavacode.CustomJavaCodeRun"%>
<%@ page import="weaver.formmode.service.CommonConstant"%>
<%@ page import="weaver.formmode.virtualform.VirtualFormHandler"%>
<%@ page import="weaver.servicefiles.BrowserXML"%>
<%@ page import="weaver.interfaces.workflow.browser.Browser"%>
<%@ page import="com.weaver.formmodel.util.StringHelper"%>
<%@ page import="weaver.conn.RecordSet"%>
<%@	page import="weaver.formmode.dao.BaseDao"%>
<%@	page import="weaver.hrm.*"%>
<%@	page import="com.weaver.formmodel.mobile.manager.MobileUserInit"%>
<%@	page import="java.io.IOException"%>
<%@	page import="java.net.URLDecoder"%>
<%@ page import="weaver.crm.CrmShareBase"%>
<%@page import="weaver.systeminfo.setting.HrmUserSettingComInfo"%>
<%@page import="weaver.hrm.companyvirtual.ResourceVirtualComInfo"%>
<%@page import="weaver.hrm.resource.ResourceComInfo"%>
<%@page import="weaver.crm.Maint.CustomerTypeComInfo"%>

<jsp:useBean id="ModeShareManager" class="weaver.formmode.view.ModeShareManager" scope="page" />
<jsp:useBean id="ModeRightInfo" class="weaver.formmode.setup.ModeRightInfo" scope="page" />
<jsp:useBean id="browserInfoService" class="weaver.formmode.service.BrowserInfoService" scope="page" />
<jsp:useBean id="CommonShareManager" class="weaver.cpt.util.CommonShareManager" scope="page" />
<jsp:useBean id="DocSearchComInfo" class="weaver.docs.search.DocSearchComInfo" scope="session"/>
<jsp:useBean id="ShareManager" class="weaver.share.ShareManager" scope="page"/>

<%
BaseBean baseBean = new BaseBean();
String action = Util.null2String(request.getParameter("action"));
String browserAction = Util.null2String(request.getParameter("browserAction"));
if(!"".equals(browserAction)){
	action = browserAction;
}
if("getListData".equals(action)){
	JSONObject resultObj = new JSONObject();
	try {
		long curr = System.currentTimeMillis();
		User user = MobileUserInit.getUser(request,response);
		
		String browserId = Util.null2String(request.getParameter("browserId"));
		String browserName = Util.null2String(request.getParameter("browserName"));
		
		int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
		int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
		
		String searchKey = "";
		try {
			searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		String sqlwhere = "";
		String poolname = "";
		String orderby = "";
		String orderbyField = "";
		String expandfield = "";
		int totalSize = 0;
		boolean single = true;
		JSONArray dataArr = new JSONArray();
		JSONArray selDataArr = new JSONArray();
		
		if(StringHelper.isNotEmpty(browserId)){
			String refsql = "select * from workflow_browserurl where id =" + browserId;
			RecordSet rs = new RecordSet();
			rs.execute(refsql);
			if(rs.next()){
				String reftable = rs.getString("tablename");
				String keyfield = rs.getString("keycolumname");
				String viewfield = rs.getString("columname");
				String fielddbtype = rs.getString("fielddbtype");
				single = (fielddbtype.equalsIgnoreCase("int") || fielddbtype.equalsIgnoreCase("integer")) ? true : false;
				int sortWay = 0;
				if(StringHelper.isEmpty(reftable) && StringHelper.isNotEmpty(browserName)){
					Browser browser = (Browser)StaticObj.getServiceByFullname(browserName, Browser.class);
					poolname = browser.getPoolname();
					String search = StringHelper.null2String(browser.getSearch()).trim();
					
					if(browser.getFrom().equals("2")){
						reftable = "(" + search + ")";
						 
						 String newtype = browserName.substring("browser.".length());
						 String sql = "select keyfield from datashowset where showname='"+newtype+"' and showclass=1 ";
						 rs.execute(sql);
						 if(rs.next()){
							 keyfield = StringHelper.null2String(rs.getString("keyfield"));
						 }
						 
						Map showfieldMap = browser.getShowfieldMap();
						Set showfieldSet = showfieldMap.keySet();
						for(Object showfieldObj : showfieldSet){
							viewfield = showfieldObj.toString() ;
							break;
						}
						
					}else{
						String[] fieldArr = search.split(",");
						//keyfield = fieldArr[0].substring(6).trim();
						String newtype = browserName.substring("browser.".length());
						String sql = "select customid from datashowset where showname='"+newtype+"' and showclass=1 ";
						rs.execute(sql);
						String customid = "";
						if(rs.next()){
							customid = StringHelper.null2String(rs.getString("customid"));
						}
						sql = "select workflow_billfield.fieldname from Mode_CustomBrowser Mode_CustomBrowser "+
						 	"left join mode_custombrowserdspfield mode_custombrowserdspfield on Mode_CustomBrowser.id=mode_custombrowserdspfield.customid "+
						 	"left join workflow_billfield workflow_billfield on workflow_billfield.id=mode_custombrowserdspfield.fieldid "+
						 	"where Mode_CustomBrowser.id="+customid+" and mode_custombrowserdspfield.ispk='1'";
						rs.execute(sql);
						if(rs.next()){
							keyfield = StringHelper.null2String(rs.getString("fieldname"));
						}
						viewfield = fieldArr[1].trim();
						expandfield = fieldArr[2].split("from")[0].trim();
						expandfield = StringHelper.isNotEmpty(expandfield) ? ("," + expandfield + " exp1") : "";
						String tableStr = search.substring(search.toLowerCase().indexOf(" from "));
						tableStr = tableStr.substring(6).trim();
						if(tableStr.indexOf(" ")==-1){
							reftable = tableStr;
						}else{
							reftable = tableStr.substring(0,tableStr.indexOf(" "));
						}
					}
					
					if("161".equals(browserId)){
						single = true;
					}else if("162".equals(browserId)){
						single = false;
					}
					
					/**增加browser框查询限定条件**/
					String pointId = browserName.replaceAll("browser.", "");
					BrowserXML browserXML = new BrowserXML();
					Hashtable dataHST = browserXML.getDataHST();
					Hashtable datadetailHST = (Hashtable)dataHST.get(pointId);
					if(datadetailHST != null){
						String customid = (String)datadetailHST.get("customid");
						if(StringHelper.isNotEmpty(customid)){
							RecordSet reS = new RecordSet();
							reS.execute("select a.defaultsql,a.searchconditiontype,a.javafilename from mode_custombrowser a where a.id="+customid);
							if(reS.next()){
								String searchconditiontype = Util.null2String(reS.getString("searchconditiontype"));
								searchconditiontype = searchconditiontype.equals("") ? "1" : searchconditiontype;
								String sqlCondition = "";
								if(searchconditiontype.equals("2")){	//java file
									String javafilename = Util.null2String(reS.getString("javafilename"));
									if(!javafilename.equals("")){
										Map<String, String> sourceCodePackageNameMap = CommonConstant.SOURCECODE_PACKAGENAME_MAP;
										String sourceCodePackageName = sourceCodePackageNameMap.get("3");
										String classFullName = sourceCodePackageName + "." + javafilename;
										
										Map<String, Object> param = new HashMap<String, Object>();
										param.put("user", user);
										
										Object javaResult = CustomJavaCodeRun.run(classFullName, param);
										sqlCondition = Util.null2String(javaResult);
									}
								}else{
									String defaultsql = Util.toScreenToEdit(reS.getString("defaultsql"),user.getLanguage()).trim();
									FormModeTransMethod formModeTransMethod = new FormModeTransMethod();
									defaultsql = formModeTransMethod.getDefaultSql(user,defaultsql);
									sqlCondition = defaultsql;
								}
								if(!sqlCondition.equals("")){
									if (sqlCondition.indexOf("$") > -1) {
										String params = Util.null2String(request.getParameter("params"));
										JSONObject paramsJson = JSONObject.fromObject(params);
										int beginIndex = sqlCondition.indexOf("$");
										while (beginIndex > -1) {
											int endIndex = sqlCondition.indexOf("$", beginIndex + 1);
											if (endIndex > -1) {
												String parentName = sqlCondition.substring(beginIndex + 1, endIndex).toLowerCase();
												String parentValue = paramsJson.getString("fieldname_" + parentName);
												sqlCondition = sqlCondition.replace("$" + parentName + "$", parentValue);
												beginIndex = sqlCondition.indexOf("$");
											} else {
												break;
											}
										}
									}
									sqlwhere = sqlwhere + " and "+sqlCondition;
								}
							}
						}
					}
				}
				
				try{
					int wIndex;
					String browserSearch = "";
					if(StringHelper.isNotEmpty(browserName) && browserName.indexOf("browser.") > -1){
						Browser browser = (Browser)StaticObj.getServiceByFullname(browserName, Browser.class);
						browserSearch = Util.null2String(browser.getSearch());
						
						if ((wIndex = browserSearch.toLowerCase().lastIndexOf("where ")) > -1) {
							String whereSearch = browserSearch.substring(wIndex + 6);
				
							String params = Util.null2String(request.getParameter("params"));
							JSONObject paramsJson = JSONObject.fromObject(params);
							//nj = $nj$ and bj = $bj$
							if (whereSearch.indexOf("$") > -1) {
								int beginIndex = whereSearch.indexOf("$");
								while (beginIndex > -1) {
									int endIndex = whereSearch.indexOf("$", beginIndex + 1);
									if (endIndex > -1) {
										String parentName = whereSearch.substring(beginIndex + 1, endIndex).toLowerCase();
										String parentValue = paramsJson.getString("fieldname_" + parentName);
										whereSearch = whereSearch.replace("$" + parentName + "$", parentValue);
										beginIndex = whereSearch.indexOf("$");
									} else {
										break;
									}
								}
							}
				
							sqlwhere = sqlwhere + " and " + whereSearch;
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
				
				String customid = "0";
				if(StringHelper.isNotEmpty(browserName)){
					String pointId = browserName.replaceAll("browser.", "");
					BrowserXML browserXML = new BrowserXML();
					Hashtable dataHST = browserXML.getDataHST();
					Hashtable datadetailHST = (Hashtable) dataHST.get(pointId);
					if (datadetailHST != null) {
						customid = (String) datadetailHST.get("customid");
					}
				}
				
				String rightsql = "";
				String sqlfrom = reftable + " t1";
				//sqlwhere = viewfield + " like '%" + searchKey + "%' " + sqlwhere + " ";
				String sqlwhere2 = viewfield + " like '%" + searchKey + "%' ";
				if("HrmDepartment".equalsIgnoreCase(reftable) || "HrmDepartmentallview".equalsIgnoreCase(reftable)){// 部门或者部门视图，要过滤掉封存的数据
					sqlwhere2 += " and (t1.canceled is null or t1.canceled=0) ";
				}else if("hrmsubcompany".equalsIgnoreCase(reftable) || "hrmsubcompanyallview".equalsIgnoreCase(reftable)){// 分部或者分部视图，要过滤掉封存的数据
					sqlwhere2 += " and (t1.canceled is null or t1.canceled=0) ";
				}
				
				//系统自定义浏览框权限过滤
				if("7".equals(browserId)||"18".equals(browserId)){
					CrmShareBase crmShareBase = new CrmShareBase();
					String leftjointable = crmShareBase.getTempTable(""+user.getUID());
					if(user.getLogintype().equals("1")){
						sqlfrom += " left join "+leftjointable+" t2 on t1.id = t2.relateditemid ";
						sqlwhere2 +=" and t1.id = t2.relateditemid ";
					}else{
						sqlwhere2 +="  and t1.deleted<>1 and t1.agent="+user.getUID();
						sqlwhere2 +="  and CRM_CustomerInfo t1 "+sqlwhere+" and t1.deleted<>1 and t1.agent="+user.getUID();
					}
				}else if("8".equals(browserId)||"135".equals(browserId)){
					sqlwhere2 +=" and ("+CommonShareManager.getPrjShareWhereByUser(user)+") ";
				}else if("9".equals(browserId)||"37".equals(browserId)){
					DocSearchComInfo.resetSearchInfo() ;
					String docstatus[] = new String[]{"1","2","5","7"};
					for(int i = 0;i<docstatus.length;i++){
					   	DocSearchComInfo.addDocstatus(docstatus[i]);
					}
					String tempsqlwhere = DocSearchComInfo.FormatSQLSearch(user.getLanguage()) ;
					tempsqlwhere+=" and (ishistory is null or ishistory = 0) ";
				    tempsqlwhere  += " and t1.id=t2.sourceid  ";
					sqlwhere2 +=" and "+tempsqlwhere;
					sqlfrom += ", "+ShareManager.getShareDetailTableByUser("doc", user) + "  t2 ";
					orderby = "doclastmoddate desc,doclastmodtime desc";
					sortWay = 1;
				}else if("16".equals(browserId)||"152".equals(browserId)||"171".equals(browserId)){
					String belongtoshow = "";		
					int userid=user.getUID();	
					String usertype = "0";
					if ("2".equals(user.getLogintype())) {
						usertype = "1";
					}
					RecordSet rswf = new RecordSet();
					rswf.executeSql("select * from HrmUserSetting where resourceId = "+userid);
					if(rswf.next()){
						belongtoshow = rswf.getString("belongtoshow");
					}
					String tempsqlwhere = " where 1 =1";
					if("171".equals(browserId)){
						tempsqlwhere +=" and workflow_requestbase.currentnodetype = 3";
					}
					if("oracle".equals(rswf.getDBType())){
						tempsqlwhere += " and (nvl(workflow_requestbase.currentstatus,-1) = -1 or (nvl(workflow_requestbase.currentstatus,-1)=0 and workflow_requestbase.creater="+user.getUID()+"))";
					} else {
						tempsqlwhere += " and (isnull(workflow_requestbase.currentstatus,-1) = -1 or (isnull(workflow_requestbase.currentstatus,-1)=0 and workflow_requestbase.creater="+user.getUID()+"))";
					}
			
					if("1".equals(belongtoshow)){
						if (rswf.getDBType().equals("oracle") || rswf.getDBType().equals("db2")) {
							sqlfrom=" ("+
							" select distinct workflow_requestbase.requestid ,requestname,creater,creatertype,createdate,createtime,createdate||' '||createtime as createtimes from workflow_requestbase , workflow_currentoperator , workflow_base" +tempsqlwhere+
							" and workflow_currentoperator.requestid = workflow_requestbase.requestid and workflow_currentoperator.userid in (" +userid + ") and workflow_currentoperator.usertype="+usertype+
							" and workflow_requestbase.workflowid = workflow_base.id and (workflow_base.isvalid='1' or workflow_base.isvalid='3') "+
							" ) t1 ";
						}else{
							sqlfrom="("+
								" select distinct workflow_requestbase.requestid ,requestname,creater,creatertype,createdate,createtime,createdate+' '+createtime as createtimes from workflow_requestbase , workflow_currentoperator , workflow_base" +tempsqlwhere+
								" and workflow_currentoperator.requestid = workflow_requestbase.requestid and workflow_currentoperator.userid in (" +userid + ") and workflow_currentoperator.usertype="+usertype+
								" and workflow_requestbase.workflowid = workflow_base.id and (workflow_base.isvalid='1' or workflow_base.isvalid='3') "+
								" ) t1 ";
						}
					}else{
						if (rswf.getDBType().equals("oracle") || rswf.getDBType().equals("db2")) {
							sqlfrom="  ("+
							" select distinct workflow_requestbase.requestid ,requestname,creater,creatertype,createdate,createtime,createdate||' '||createtime as createtimes from workflow_requestbase , workflow_currentoperator , workflow_base" +tempsqlwhere+
							" and workflow_currentoperator.requestid = workflow_requestbase.requestid and workflow_currentoperator.userid=" +userid + " and workflow_currentoperator.usertype="+usertype+
							" and workflow_requestbase.workflowid = workflow_base.id and (workflow_base.isvalid='1' or workflow_base.isvalid='3') "+
							" ) t1 ";
						}else{
							sqlfrom=" ("+
								" select distinct workflow_requestbase.requestid ,requestname,creater,creatertype,createdate,createtime,createdate+' '+createtime as createtimes from workflow_requestbase , workflow_currentoperator , workflow_base" +tempsqlwhere+
								" and workflow_currentoperator.requestid = workflow_requestbase.requestid and workflow_currentoperator.userid=" +userid + " and workflow_currentoperator.usertype="+usertype+
								" and workflow_requestbase.workflowid = workflow_base.id and (workflow_base.isvalid='1' or workflow_base.isvalid='3') "+
								" ) t1 ";
						}
					}
					orderby  = "createdate desc , createtime desc";
				}else if("137".equals(browserId)){
					RecordSet rscar = new RecordSet();
					rscar.executeSql("select carsdetachable from SystemSet");
					int detachable=0;
					if(rscar.next()){
					    detachable=rscar.getInt(1);
					}
					int userid=user.getUID();
					if(detachable==1){
						if(userid!=1){
							String sqltmp = "";
							String blonsubcomid="";
							char flag=Util.getSeparator();
							rscar.executeProc("HrmRoleSR_SeByURId", ""+userid+flag+"Car:Maintenance");
							while(rscar.next()){
								blonsubcomid=rscar.getString("subcompanyid");
								sqltmp += (", "+blonsubcomid);
							}
							if(!"".equals(sqltmp)){//角色设置的权限
								sqltmp = sqltmp.substring(1);
								sqlwhere2 += " and subcompanyid in ("+sqltmp+") ";
							}else{
								sqlwhere2 += " and subcompanyid="+user.getUserSubCompany1() ;
							}
						}
					}
					sortWay = 1;
					single = true;
				}else if("23".equals(browserId)){
					RecordSet rscap = new RecordSet();
					rscap.executeSql("select cptdetachable from SystemSet");
					int detachable=0;
					if(rscap.next()){
					   detachable=rscap.getInt("cptdetachable");
					}
					int userid=user.getUID();
					int belid = user.getUserSubCompany1();
					char flag=Util.getSeparator();
					String rightStr = "";
					if(HrmUserVarify.checkUserRight("Capital:Maintenance",user)){
						rightStr = "Capital:Maintenance";
					}
			
					sqlwhere2 += " and isdata = '2' ";
					if(detachable == 1 && userid!=1){
						String sqltmp = "";
						String blonsubcomid="";
						rscap.executeProc("HrmRoleSR_SeByURId", ""+userid+flag+rightStr);
						while(rscap.next()){
						    blonsubcomid=rscap.getString("subcompanyid");
							sqltmp += (", "+blonsubcomid);
						}
						if(!"".equals(sqltmp)){//角色设置的权限
							sqltmp = sqltmp.substring(1);
							sqlwhere2 += " and blongsubcompany in ("+sqltmp+") ";
						}else{
							sqlwhere2 += " and blongsubcompany in ("+belid+") ";
						}
					}
					CommonShareManager.setAliasTableName("t2");
					sqlwhere2+= " and exists(select 1 from CptCapitalShareInfo t2 where t2.relateditemid=t1.id and ("+CommonShareManager.getShareWhereByUser("cpt", user)+") ) ";
					
					if("oracle".equalsIgnoreCase(rscap.getDBType())){
						sqlwhere2 += " and (nvl(capitalnum,0)-nvl(frozennum,0))>0 ";
					}else{
						sqlwhere2 += " and (isnull(capitalnum,0)-isnull(frozennum,0))>0 ";
					}
				}
				
				sqlwhere = sqlwhere2 + sqlwhere + " ";
				
				if(!"0".equals(customid) && customid != null){
					String formID = "0";
					String formmodeid = "0";
					RecordSet reS = new RecordSet();
					reS.execute("select a.modeid,a.customname,a.customdesc,a.formid from  mode_custombrowser a where  a.id=" + customid);
					if (reS.next()) {
						formID = Util.null2String(reS.getString("formid"));
						formmodeid = Util.null2String(reS.getString("modeid"));
					}
					
					boolean isVirtualForm = VirtualFormHandler.isVirtualForm(formID);
					//虚拟表单需求重新获取主键
					if(isVirtualForm){
						Map<String, Object> vFormInfo = new HashMap<String, Object>();
						vFormInfo = VirtualFormHandler.getVFormInfo(formID);
						keyfield = Util.null2String(vFormInfo.get("vprimarykey"));	//虚拟表单主键列名称
					}
					if(!isVirtualForm){// 虚拟表单不考虑权限
						List<User> lsUser = ModeRightInfo.getAllUserCountList(user);
						if (formmodeid.equals("") || formmodeid.equals("0")) {// 浏览框中没有设置模块
							String sqlStr1 = "select id,modename from modeinfo where formid=" + formID + " order by id";
							RecordSet rs1 = new RecordSet();
							rs1.executeSql(sqlStr1);
							while (rs1.next()) {
								String mid = rs1.getString("id");
								ModeShareManager.setModeId(Util.getIntValue(mid, 0));
								for (int i = 0; i < lsUser.size(); i++) {
									User tempUser = lsUser.get(i);
									String tempRightStr = ModeShareManager.getShareDetailTableByUser("formmode", tempUser);
									if (rightsql.isEmpty()) {
										rightsql += tempRightStr;
									} else {
										rightsql += " union  all " + tempRightStr;
									}
								}
							}
							if (!rightsql.isEmpty()) {
								rightsql = " (SELECT  sourceid,MAX(sharelevel) AS sharelevel from ( " + rightsql + " ) temptable group by temptable.sourceid) ";
							}
						} else {
							ModeShareManager.setModeId(Util.getIntValue(formmodeid, 0));
							for (int i = 0; i < lsUser.size(); i++) {
								User tempUser = (User) lsUser.get(i);
								String tempRightStr = ModeShareManager.getShareDetailTableByUser("formmode", tempUser);
								if (rightsql.isEmpty()) {
									rightsql += tempRightStr;
								} else {
									rightsql += " union  all " + tempRightStr;
								}
							}
							if (!rightsql.isEmpty()) {
								rightsql = " (SELECT  sourceid,MAX(sharelevel) AS sharelevel from ( " + rightsql + " ) temptable group by temptable.sourceid) ";
							}
						}
					}
					
					if (StringHelper.isNotEmpty(rightsql)) {
						if("browser.zdinfo".equals(browserName)){
							sqlfrom = " from "+sqlfrom+","+rightsql+" t2 ";
							sqlwhere = sqlwhere.trim();
							if(StringHelper.isNotEmpty(sqlwhere)){
								if(sqlwhere.startsWith("and")){
									sqlwhere = " t1.id = t2.sourceid "+sqlwhere;
								}else{
									sqlwhere = " t1.id = t2.sourceid and "+sqlwhere;
								}
							}else{
								sqlwhere = " t1.id = t2.sourceid ";
							}
						}else{
							List<Map<String, Object>> selectDataList1 = new ArrayList<Map<String, Object>>();
							BaseDao baseDao1 = new BaseDao();
							selectDataList1 = baseDao1.getResultByList(rightsql);
							if(!selectDataList1.isEmpty()){
								if(selectDataList1.size() > 1){
									sqlwhere += " and t1.id in (";
									String sourceids = "";
									for(Map<String, Object> map : selectDataList1){
						    	 		String sourceid = Util.null2String(map.get("sourceid"));
										sourceids += ("," + sourceid);
						    	 	}
						    	 	sqlwhere += (sourceids.substring(1) + ") ");
								}else{
									String sourceid = Util.null2String(selectDataList1.get(0).get("sourceid"));
									sqlwhere += (" and t1.id = "+sourceid);
								}
					    	 }
						}
					}
					orderby = browserInfoService.getOrderSQL(customid);
				}
				if(StringHelper.isEmpty(keyfield)){
					keyfield = "id";
				}
				if(!"".equals(orderby)){
					String orderbyStr = orderby.toLowerCase().replaceAll("t1.","").replaceAll("asc","").replaceAll("desc","");
					List orderbyList = StringHelper.string2ArrayList(orderbyStr,",");
					for(int idx = 0; idx < orderbyList.size(); idx++){
						String orderbyFColumnName = StringHelper.null2String(orderbyList.get(idx)).trim();
						if(!viewfield.toLowerCase().equals(orderbyFColumnName) && !keyfield.toLowerCase().equals(orderbyFColumnName)){
							orderbyField += ","+orderbyFColumnName;
						}
					}
				}

				if(StringHelper.isEmpty(keyfield)){
					keyfield = "id";
				}
				
				SplitPageParaBean spp = new SplitPageParaBean();
				spp.setSqlFrom(sqlfrom);
				spp.setPrimaryKey(keyfield);
				if(keyfield.equalsIgnoreCase(viewfield)){
     				spp.setBackFields(viewfield + expandfield + orderbyField);
			    }else{
			     	spp.setBackFields(keyfield + "," + viewfield + expandfield + orderbyField);
			    }
				spp.setSqlWhere(sqlwhere);
				spp.setPoolname(poolname);
				spp.setSqlOrderBy(orderby);
				spp.setSortWay(sortWay);
				SplitPageUtil spu = new SplitPageUtil();
				spu.setSpp(spp);
				RecordSet rs2 = spu.getCurrentPageRs(pageNo,pageSize);
				totalSize = spu.getRecordCount();
				while(rs2.next()) {
					String objid = rs2.getString(keyfield);
					String objname = rs2.getString(viewfield);
					String objname2 = rs2.getString("exp1");
					
					JSONObject jsonObj = new JSONObject();
					jsonObj.put("id",objid);
					jsonObj.put("objname",objname);
					jsonObj.put("objname2", objname2);
					dataArr.add(jsonObj);
				}
				
				String selectedIds = Util.null2String(request.getParameter("selectedIds"));
				if(!selectedIds.equals("")){
					String sqlIds = StringHelper.formatMutiIDs(selectedIds);
					String sqlSel = "select " + keyfield + "," + viewfield + expandfield + " from " + reftable + " t1 where t1." + keyfield + " in (" + sqlIds + ")";
					RecordSet rsSel = new RecordSet();
					if (!"".equals(poolname)) {
						rsSel.executeSql(sqlSel, poolname);
					} else {
						rsSel.executeSql(sqlSel);
					}
					
					while(rsSel.next()) {
						String objid = rsSel.getString(keyfield);
						String objname = rsSel.getString(viewfield);
						String objname2 = rsSel.getString("exp1");
						
						JSONObject jsonObj = new JSONObject();
						jsonObj.put("id",objid);
						jsonObj.put("objname",objname);
						jsonObj.put("objname2", objname2);
						selDataArr.add(jsonObj);
					}
				}
			}
		}

		long curr2 = System.currentTimeMillis() - curr;
		
		resultObj.put("time", curr2);
		resultObj.put("single", single);
		resultObj.put("totalSize", totalSize);
		resultObj.put("datas", dataArr);
		resultObj.put("sel_datas", selDataArr);
		resultObj.put("status", "1");
	} catch (Exception ex) {
		ex.printStackTrace();
		resultObj.put("status", "0");
		resultObj.put("errMsg", ex.getMessage());
	}finally{
		try{
			out.print(resultObj.toString());
			out.flush();
		}catch(IOException ex){
			ex.printStackTrace();
		}
	}
}else if("getMeetingTypeListData".equals(action)){
	JSONObject resultObj = new JSONObject();
	try {
		long curr = System.currentTimeMillis();
		User user = MobileUserInit.getUser(request,response);
		
		int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
		int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
		
		String searchKey = "";
		String sqlwhere = " 1=1 ";
		try {
			searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
			if(!"".equals(searchKey)){
				sqlwhere += " and a.name like '%"+searchKey+"%' ";
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		
		List<User> userList=new ArrayList<User>();
		userList.add(user);
		boolean isShowBelongto = false;
		if("0".equals(user.getAccount_type())){
			try {
				HrmUserSettingComInfo userSetting=new HrmUserSettingComInfo();
				String belongtoshow = userSetting.getBelongtoshowByUserId(user.getUID()+"");
				isShowBelongto = "1".equals(belongtoshow);
			} catch (Exception e) {
				isShowBelongto = false;
			}
		}else{
			isShowBelongto = false;
		}
		if(isShowBelongto){
			List tempUserList=User.getBelongtoUsersByUserId(user.getUID());
			if(tempUserList!=null) userList.addAll(tempUserList);
		}
		User tempUser=null;
		ResourceVirtualComInfo rsv=new ResourceVirtualComInfo();;

		StringBuffer sql=new StringBuffer();
		sql.append(" and exists (");
		for(int i=0;i<userList.size();i++){
			tempUser=userList.get(i);
			String deptids=tempUser.getUserDepartment()+"";
			String compids=tempUser.getUserSubCompany1()+","+tempUser.getUserSubCompany2()+","+tempUser.getUserSubCompany3()+","+tempUser.getUserSubCompany4();
			if(rsv!=null){
		    	String vDeptId=rsv.getDepartmentids(tempUser.getUID()+"");
		    	if(!"".equals(vDeptId)){
		    		deptids+=","+vDeptId;
		    	}
		    	String vCompId=rsv.getSubcompanyids(tempUser.getUID()+"");
		    	if(!"".equals(vCompId)){
		    		compids+=","+vCompId;
		    	}
		    }
			sql.append(i==0?"":"  UNION ALL  ");
			sql.append(" SELECT 1 FROM MeetingType_share b where a.id = b.mtid and b.departmentid in ("+deptids+") and b.deptlevel <= "+tempUser.getSeclevel()+" AND b.deptlevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 1 ");
			sql.append(" UNION ALL ");
			sql.append(" SELECT 1 FROM MeetingType_share b where a.id = b.mtid and b.subcompanyid in ("+compids+") and b.sublevel <= "+tempUser.getSeclevel()+" and b.sublevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 6 ");
		    sql.append(" UNION ALL ");
		    sql.append(" SELECT 1 FROM MeetingType_share b where a.id = b.mtid and b.seclevel <= "+tempUser.getSeclevel()+" and b.seclevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 3 ");
		    sql.append(" UNION ALL ");
		    sql.append(" SELECT 1 FROM MeetingType_share b where a.id = b.mtid AND b.userid = "+tempUser.getUID()+" AND b.permissiontype = 5 ");
		    sql.append(" UNION ALL ");
		    sql.append(" SELECT 1 FROM MeetingType_share b, hrmRoleMembers hr WHERE a.id = b.mtid AND hr.roleid = b.roleid AND hr.resourceid = "+tempUser.getUID()+" AND hr.rolelevel >= b.rolelevel AND b.roleseclevel <= "+tempUser.getSeclevel()+" and b.roleseclevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 2  ");
		}
		sql.append(") ");
		sqlwhere += sql.toString();
		
		String poolname = "";
		String orderby = "";
		String orderbyField = "";
		String expandfield = "";
		int totalSize = 0;
		boolean single = true;
		JSONArray dataArr = new JSONArray();
		JSONArray selDataArr = new JSONArray();
		
		SplitPageParaBean spp = new SplitPageParaBean();
		
		String backFields =" a.id,a.dsporder,a.name,a.subcompanyid,a.desc_n,a.approver,a.approver1 ";
		String fromSql = " Meeting_Type a ";
		String orderBy = " a.dsporder,a.name ";
		spp.setSqlFrom(fromSql);
		spp.setPrimaryKey("a.id");
		spp.setBackFields(backFields);
		spp.setSqlWhere(sqlwhere);
		spp.setPoolname(poolname);
		spp.setSqlOrderBy(orderBy);
		spp.setSortWay(0);
		SplitPageUtil spu = new SplitPageUtil();
		spu.setSpp(spp);
		RecordSet rs2 = spu.getCurrentPageRs(pageNo,pageSize);
		totalSize = spu.getRecordCount();
		while(rs2.next()) {
			String objid = rs2.getString("id");
			String objname = rs2.getString("name");
			String objname2 = rs2.getString("exp1");
			
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("id",objid);
			jsonObj.put("objname",objname);
			jsonObj.put("objname2", objname2);
			dataArr.add(jsonObj);
		}
		long curr2 = System.currentTimeMillis() - curr;
		resultObj.put("time", curr2);
		resultObj.put("single", single);
		resultObj.put("totalSize", totalSize);
		resultObj.put("datas", dataArr);
		resultObj.put("sel_datas", selDataArr);
		resultObj.put("status", "1");
	} catch (Exception ex) {
		ex.printStackTrace();
		resultObj.put("status", "0");
		resultObj.put("errMsg", ex.getMessage());
	}finally{
		try{
			out.print(resultObj.toString());
			out.flush();
		}catch(IOException ex){
			ex.printStackTrace();
		}
	}
}else if("getMeetingRoomListData".equals(action)){
	JSONObject resultObj = new JSONObject();
	try {
		long curr = System.currentTimeMillis();
		User user = MobileUserInit.getUser(request,response);
		
		int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
		int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
		
		String searchKey = "";
		String sqlwhere = " 1=1 and (a.status=1 or a.status is null ) ";
		try {
			searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
			if(!"".equals(searchKey)){
				sqlwhere += " and a.name like '%"+searchKey+"%' ";
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		
		List<User> userList=new ArrayList<User>();
		userList.add(user);
		boolean isShowBelongto = false;
		if("0".equals(user.getAccount_type())){
			try {
				HrmUserSettingComInfo userSetting=new HrmUserSettingComInfo();
				String belongtoshow = userSetting.getBelongtoshowByUserId(user.getUID()+"");
				isShowBelongto = "1".equals(belongtoshow);
			} catch (Exception e) {
				isShowBelongto = false;
			}
		}else{
			isShowBelongto = false;
		}
		if(isShowBelongto){
			List tempUserList=User.getBelongtoUsersByUserId(user.getUID());
			if(tempUserList!=null) userList.addAll(tempUserList);
		}
		User tempUser=null;
		ResourceVirtualComInfo rsv=new ResourceVirtualComInfo();;

		StringBuffer sql=new StringBuffer();
		sql.append(" and exists (");
		for(int i=0;i<userList.size();i++){
			tempUser=userList.get(i);
			String deptids=tempUser.getUserDepartment()+"";
			String compids=tempUser.getUserSubCompany1()+","+tempUser.getUserSubCompany2()+","+tempUser.getUserSubCompany3()+","+tempUser.getUserSubCompany4();
			if(rsv!=null){
		    	String vDeptId=rsv.getDepartmentids(tempUser.getUID()+"");
		    	if(!"".equals(vDeptId)){
		    		deptids+=","+vDeptId;
		    	}
		    	String vCompId=rsv.getSubcompanyids(tempUser.getUID()+"");
		    	if(!"".equals(vCompId)){
		    		compids+=","+vCompId;
		    	}
		    }
			sql.append(i==0?"":"  UNION ALL  ");
			sql.append(" SELECT 1 FROM MeetingRoom_share b where a.id = b.mid and b.departmentid in ("+deptids+") and b.deptlevel <= "+tempUser.getSeclevel()+" AND b.deptlevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 1 ");
			sql.append(" UNION ALL ");
			sql.append(" SELECT 1 FROM MeetingRoom_share b where a.id = b.mid and b.subcompanyid in ("+compids+") and b.sublevel <= "+tempUser.getSeclevel()+" and b.sublevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 6 ");
		    sql.append(" UNION ALL ");
		    sql.append(" SELECT 1 FROM MeetingRoom_share b where a.id = b.mid and b.seclevel <= "+tempUser.getSeclevel()+" and b.seclevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 3 ");
		    sql.append(" UNION ALL ");
		    sql.append(" SELECT 1 FROM MeetingRoom_share b where a.id = b.mid AND b.userid = "+tempUser.getUID()+" AND b.permissiontype = 5 ");
		    sql.append(" UNION ALL ");
		    sql.append(" SELECT 1 FROM MeetingRoom_share b, hrmRoleMembers hr WHERE a.id = b.mid AND hr.roleid = b.roleid AND hr.resourceid = "+tempUser.getUID()+" AND hr.rolelevel >= b.rolelevel AND b.roleseclevel <= "+tempUser.getSeclevel()+" and b.roleseclevelMax >= "+tempUser.getSeclevel()+" AND b.permissiontype = 2  ");
		}
		sql.append(") ");
		sqlwhere += sql.toString();
		
		String poolname = "";
		String orderby = "";
		String orderbyField = "";
		String expandfield = "";
		int totalSize = 0;
		boolean single = true;
		JSONArray dataArr = new JSONArray();
		JSONArray selDataArr = new JSONArray();
		
		SplitPageParaBean spp = new SplitPageParaBean();
		
		String backFields =" a.id,a.name,a.subcompanyid,a.roomdesc,a.dsporder ";
		String fromSql = " MeetingRoom a ";
		String orderBy = "a.dsporder,a.name";
		spp.setSqlFrom(fromSql);
		spp.setPrimaryKey("a.id");
		spp.setBackFields(backFields);
		spp.setSqlWhere(sqlwhere);
		spp.setPoolname(poolname);
		spp.setSqlOrderBy(orderBy);
		spp.setSortWay(0);
		SplitPageUtil spu = new SplitPageUtil();
		spu.setSpp(spp);
		RecordSet rs2 = spu.getCurrentPageRs(pageNo,pageSize);
		totalSize = spu.getRecordCount();
		while(rs2.next()) {
			String objid = rs2.getString("id");
			String objname = rs2.getString("name");
			String objname2 = rs2.getString("exp1");
			
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("id",objid);
			jsonObj.put("objname",objname);
			jsonObj.put("objname2", objname2);
			dataArr.add(jsonObj);
		}
		long curr2 = System.currentTimeMillis() - curr;
		resultObj.put("time", curr2);
		resultObj.put("single", single);
		resultObj.put("totalSize", totalSize);
		resultObj.put("datas", dataArr);
		resultObj.put("sel_datas", selDataArr);
		resultObj.put("status", "1");
	} catch (Exception ex) {
		ex.printStackTrace();
		resultObj.put("status", "0");
		resultObj.put("errMsg", ex.getMessage());
	}finally{
		try{
			out.print(resultObj.toString());
			out.flush();
		}catch(IOException ex){
			ex.printStackTrace();
		}
	}
}else if("getCustomerListData".equals(action)){
	JSONObject resultObj = new JSONObject();
	try {
		long curr = System.currentTimeMillis();
		User user = MobileUserInit.getUser(request,response);
		String userid = String.valueOf(user.getUID());
		
		int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
		int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
		
		String searchKey = "";
		String sqlwhere = " where t1.deleted<>1 and t1.id = t2.relateditemid ";
		try {
			searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
			if(!"".equals(searchKey)){
				sqlwhere += " and t1.name like '%"+searchKey+"%' ";
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		String leftjointable = "";
		RecordSet recordSet=new RecordSet();
		ResourceComInfo ResourceComInfo = new ResourceComInfo();
		ResourceVirtualComInfo resourceVirtualComInfo = new ResourceVirtualComInfo();
		CustomerTypeComInfo CustomerTypeComInfo = new CustomerTypeComInfo();
		String temptalbe = "";
    	if(recordSet.getDBType().equals("oracle")){
            try {
	            int userlevel = Util.getIntValue(ResourceComInfo.getSeclevel(userid),0);
	            int userDeptid = Util.getIntValue(ResourceComInfo.getDepartmentID(userid),-1);
	            int userSubid = Util.getIntValue(ResourceComInfo.getSubCompanyID(userid),-1);
	            
	            String jobtitleid = ResourceComInfo.getJobTitle(userid);
	            
	            String rolesql =" exists (select id from hrmrolemembers  where resourceid="+userid+" and contents=roleid) and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax";
	            
	            boolean isSystemManager = false;
	            recordSet.executeSql("select 1 from hrmresourcemanager where id="+userid);
	            if(recordSet.getCounts()>0) {
	            	isSystemManager = true;
	            }
	            if(isSystemManager){
	            	temptalbe=" deleted =0 ";
	            }else{
	            	String[] virtualDeptids=Util.TokenizerString2(Util.null2String(resourceVirtualComInfo.getDepartmentids(userid)), ",");
		    		String[] virtualSubids=Util.TokenizerString2(Util.null2String(resourceVirtualComInfo.getSubcompanyids(userid)), ",");
		            
		            String deptSql=" or (sharetype=2 and contents="+userDeptid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax )";
		    		for(String deptid:virtualDeptids){
		    			deptSql+=" or (sharetype=2 and contents="+deptid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax) ";
		    		}
		    		
		    		String subSql=" or (sharetype=5 and contents="+userSubid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax ) ";
		    		for(String subid:virtualSubids){
		    			subSql+=" or( sharetype=5 and contents="+subid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax) ";
		    		}
		    		
		    		String jobtitleidSql=" or (sharetype=6 and jobtitleid like '%,"+jobtitleid+",%' and  joblevel = 0 ) " +
		    		"  or (sharetype=6 and jobtitleid like '%,"+jobtitleid+",%' and  joblevel = 1 and scopeid like '%,"+userDeptid+",%')  "+
		    		"  or (sharetype=6 and jobtitleid like '%,"+jobtitleid+",%' and  joblevel = 2 and scopeid like '%,"+userSubid+",%' )  ";
		    		
		            
		            temptalbe = " deleted =0 and ("+
                    "(sharetype=1 and contents="+userid+") "+
                    deptSql+
                    subSql+
                    jobtitleidSql+
                    " or (sharetype=3 and "+rolesql+" ) "+
                    " or (sharetype=4 and contents=1 and seclevel<="+userlevel+" and seclevelMax >= "+userlevel+")" +
                    " or (sharetype=9 and contents="+userid+")"+
                    ") ";
	            }
            }catch (Exception e) {}
    		leftjointable = "(select distinct relateditemid from CRM_ShareInfo where "+temptalbe+")";
    	}else{
    		try {
	    	        int userlevel = Util.getIntValue(ResourceComInfo.getSeclevel(userid),0);
	    	        int userDeptid = Util.getIntValue(ResourceComInfo.getDepartmentID(userid),-1);
	    	        int userSubid = Util.getIntValue(ResourceComInfo.getSubCompanyID(userid),-1);
	    	        
	    	        String jobtitleid = ResourceComInfo.getJobTitle(userid);
	    	        
	    	        String rolesql =" exists (select id from hrmrolemembers  where resourceid="+userid+" and contents=roleid) and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax";
	    	        
	    	        boolean isSystemManager = false;
		            recordSet.executeSql("select 1 from hrmresourcemanager where id="+userid);
		            if(recordSet.getCounts()>0) {
		            	isSystemManager = true;
		            }
	    	        
	    	        if(isSystemManager){
	    	        	temptalbe="( select relateditemid from CRM_ShareInfo where deleted =0 ) t ";
	    	        }else{
	    	        	String[] virtualDeptids=Util.TokenizerString2(Util.null2String(resourceVirtualComInfo.getDepartmentids(userid)), ",");
	        			String[] virtualSubids=Util.TokenizerString2(Util.null2String(resourceVirtualComInfo.getSubcompanyids(userid)), ",");
	        	        
	        	        String deptSql=" select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=2 and contents="+userDeptid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax  UNION all ";
	        			for(String deptid:virtualDeptids){
	        				deptSql+=" select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=2 and contents="+deptid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax UNION all ";
	        			}
	        			
	        			String subSql=" select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=5 and contents="+userSubid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax UNION all ";
	        			for(String subid:virtualSubids){
	        				subSql+=" select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=5 and contents="+subid+" and "+userlevel+">=seclevel and "+userlevel+" <= seclevelMax UNION all ";
	        			}
	        			
	        			String jobtitleidSql=" select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=6 and jobtitleid like '%,"+jobtitleid+",%' and  joblevel = 0 UNION all " +
	        			"  select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=6 and jobtitleid like '%,"+jobtitleid+",%' and  joblevel = 1 and scopeid like '%,"+userDeptid+",%' UNION all  "+
	        			"  select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=6 and jobtitleid like '%,"+jobtitleid+",%' and  joblevel = 2 and scopeid like '%,"+userSubid+",%'  UNION all  ";
	        					
	        	        
	        	        temptalbe = " ("+
	        	                        " select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=1 and contents="+userid+" UNION all "+
	        	                        deptSql+
	        	                        subSql+
	        	                        jobtitleidSql+                        
	        	                        " select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=3 and "+rolesql+"  UNION all "+
	        	                        " select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=4 and contents=1 and seclevel<="+userlevel+" and seclevelMax >= "+userlevel+" UNION all " +
	        	                        " select relateditemid from CRM_ShareInfo where deleted =0 and sharetype=9 and contents="+userid+
	        	                     " ) t ";
	    	        }
    	    }catch (Exception e) {}
    		leftjointable = "(select distinct relateditemid from "+temptalbe+")";
    	}

		//娣诲姞鍒ゆ柇鏉冮檺鐨勫唴瀹?-new*/
		String sqlfrom = "";
		if(user.getLogintype().equals("1")){
			sqlfrom = "CRM_CustomerInfo t1 left join "+leftjointable+" t2 on t1.id = t2.relateditemid";
		}else{
			sqlfrom = "CRM_CustomerInfo t1";
		}
		String poolname = "";
		int totalSize = 0;
		boolean single = false;
		JSONArray dataArr = new JSONArray();
		JSONArray selDataArr = new JSONArray();
		
		SplitPageParaBean spp = new SplitPageParaBean();
		
		String backFields =" t1.id,t1.name,t1.crmcode,t1.type,t1.city,t1.country,t1.department ";
		spp.setSqlFrom(sqlfrom);
		spp.setPrimaryKey("t1.id");
		spp.setBackFields(backFields);
		spp.setSqlWhere(sqlwhere);
		spp.setPoolname(poolname);
		spp.setDistinct(true);
		spp.setSortWay(spp.DESC);
		SplitPageUtil spu = new SplitPageUtil();
		spu.setSpp(spp);
		RecordSet rs2 = spu.getCurrentPageRs(pageNo,pageSize);
		totalSize = spu.getRecordCount();
		while(rs2.next()) {
			String objid = rs2.getString("id");
			String objname = rs2.getString("name");
			String objname2 = rs2.getString("type");
			
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("id",objid);
			jsonObj.put("objname",objname);
			jsonObj.put("objname2", CustomerTypeComInfo.getCustomerTypename(objname2));
			dataArr.add(jsonObj);
		}
		long curr2 = System.currentTimeMillis() - curr;
		resultObj.put("time", curr2);
		resultObj.put("single", single);
		resultObj.put("totalSize", totalSize);
		resultObj.put("datas", dataArr);
		resultObj.put("sel_datas", selDataArr);
		resultObj.put("status", "1");
	} catch (Exception ex) {
		ex.printStackTrace();
		resultObj.put("status", "0");
		resultObj.put("errMsg", ex.getMessage());
	}finally{
		try{
			out.print(resultObj.toString());
			out.flush();
		}catch(IOException ex){
			ex.printStackTrace();
		}
	}
}else if("getRoleListData".equals(action)){
	JSONObject resultObj = new JSONObject();
	try {
		long curr = System.currentTimeMillis();
		User user = MobileUserInit.getUser(request,response);
		String userid = String.valueOf(user.getUID());
		
		int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
		int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
		
		String searchKey = "";
		String sqlwhere = " where 1=1 ";
		try {
			searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
			if(!"".equals(searchKey)){
				sqlwhere += " and (a.rolesname like '%"+searchKey+"%' or a.rolesmark like '%"+searchKey+"%') ";
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		String poolname = "";
		int totalSize = 0;
		boolean single = false;
		JSONArray dataArr = new JSONArray();
		JSONArray selDataArr = new JSONArray();
		
		SplitPageParaBean spp = new SplitPageParaBean();
		
		String backFields =" a.id,a.rolesname,a.rolesmark ";
		spp.setSqlFrom(" from HrmRoles a ");
		spp.setPrimaryKey("a.id");
		spp.setBackFields(backFields);
		spp.setSqlWhere(sqlwhere);
		spp.setPoolname(poolname);
		spp.setDistinct(true);
		spp.setSortWay(spp.ASC);
		SplitPageUtil spu = new SplitPageUtil();
		spu.setSpp(spp);
		RecordSet rs2 = spu.getCurrentPageRs(pageNo,pageSize);
		totalSize = spu.getRecordCount();
		while(rs2.next()) {
			String objid = rs2.getString("id");
			String objname = rs2.getString("rolesname");
			String objname2 = rs2.getString("rolesmark");
			
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("id",objid);
			jsonObj.put("objname",objname);
			jsonObj.put("objname2", objname2);
			dataArr.add(jsonObj);
		}
		long curr2 = System.currentTimeMillis() - curr;
		resultObj.put("time", curr2);
		resultObj.put("single", single);
		resultObj.put("totalSize", totalSize);
		resultObj.put("datas", dataArr);
		resultObj.put("sel_datas", selDataArr);
		resultObj.put("status", "1");
	} catch (Exception ex) {
		ex.printStackTrace();
		resultObj.put("status", "0");
		resultObj.put("errMsg", ex.getMessage());
	}finally{
		try{
			out.print(resultObj.toString());
			out.flush();
		}catch(IOException ex){
			ex.printStackTrace();
		}
	}
}else if("getJobsListData".equals(action)){
	JSONObject resultObj = new JSONObject();
	try {
		long curr = System.currentTimeMillis();
		User user = MobileUserInit.getUser(request,response);
		String userid = String.valueOf(user.getUID());
		
		int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
		int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
		
		String searchKey = "";
		String sqlwhere = " where 1=1 and a.id = b.jobgroupid and b.id = c.jobactivityid ";
		try {
			searchKey = URLDecoder.decode(Util.null2String(request.getParameter("searchKey")), "utf-8");
			if(!"".equals(searchKey)){
				sqlwhere += " and (c.jobtitlename like '%"+searchKey+"%' or c.jobtitlemark like '%"+searchKey+"%') ";
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		String poolname = "";
		int totalSize = 0;
		boolean single = false;
		JSONArray dataArr = new JSONArray();
		JSONArray selDataArr = new JSONArray();
		
		SplitPageParaBean spp = new SplitPageParaBean();
		
		String backFields =" c.id,c.jobtitlemark,c.jobtitlename,a.jobgroupname,b.jobactivitymark ";
		spp.setSqlFrom("HrmJobGroups a,HrmJobActivities b,HrmJobTitles c");
		spp.setPrimaryKey("c.id");
		spp.setBackFields(backFields);
		spp.setSqlWhere(sqlwhere);
		spp.setSqlOrderBy("c.jobtitlemark");
		spp.setPoolname(poolname);
		spp.setDistinct(true);
		spp.setSortWay(spp.ASC);
		SplitPageUtil spu = new SplitPageUtil();
		spu.setSpp(spp);
		RecordSet rs2 = spu.getCurrentPageRs(pageNo,pageSize);
		totalSize = spu.getRecordCount();
		while(rs2.next()) {
			String objid = rs2.getString("id");
			String objname = rs2.getString("jobtitlename");
			String objname2 = rs2.getString("jobgroupname");
			
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("id",objid);
			jsonObj.put("objname",objname);
			jsonObj.put("objname2", objname2);
			dataArr.add(jsonObj);
		}
		long curr2 = System.currentTimeMillis() - curr;
		resultObj.put("time", curr2);
		resultObj.put("single", single);
		resultObj.put("totalSize", totalSize);
		resultObj.put("datas", dataArr);
		resultObj.put("sel_datas", selDataArr);
		resultObj.put("status", "1");
	} catch (Exception ex) {
		ex.printStackTrace();
		resultObj.put("status", "0");
		resultObj.put("errMsg", ex.getMessage());
	}finally{
		try{
			out.print(resultObj.toString());
			out.flush();
		}catch(IOException ex){
			ex.printStackTrace();
		}
	}
}
%>
